﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace L9SUBSETDLG
{
    public partial class PerformanceSet : Form
    {

        public string[] m_clockList={};//时钟频率数组
        public string[] m_grayList={};//时钟频率数组
        public int m_ncurclockselect=0;//时钟频率选择index
        public int m_ncurgrayslect=0;//灰度等级选择index
        public string m_strgrayindextext;//选择的灰度等级文本
        public string m_nclockduty="50";//占空比
        public string m_ngraystart="1";//缺省起灰值
        public string m_low_gray_smooth="1";//缺省低灰平滑度
        public string m_ngama="2.8";//gama值
        public bool m_bopenprotect=false;//开机渐亮保护
        public bool m_bcolorRe=false;//色彩还原标志
        public bool m_bReciveWidth=false;//拓展接收卡截取宽度
        public bool m_bNsigle = true;//无信号时显示最后一帧
        public int m_eadjust = 0;//通道电流显示状态，默认为0不显示
        public bool m_cProtectCP = false;//保持屏体连接和调光调色参数
        public PerformanceSet()
        {
            InitializeComponent();
            //事件添加
            textBox_clockduty.TextChanged+=textBox_clockduty_TextChanged;
            textBox_graystart.TextChanged+=textBox_graystart_TextChanged;
            textBox_low_gray_smooth.TextChanged+=textBox_low_gray_smooth_TextChanged;
            textBox_gamavalue.TextChanged+=textBox_gamavalue_TextChanged;
            comboBox_clocklist.SelectedIndexChanged+=comboBox_clocklist_SelectedIndexChanged;
            comboBox_grayLevelList.SelectedIndexChanged+=comboBox_grayLevelList_SelectedIndexChanged;
        }
        public void SetclockList(string []clocklist)
        {
            m_clockList = clocklist;
        }
        public void SetGrayList(string[] graylist)
        {
            m_grayList = graylist;
        }

        public void initForm()
        {
            //更新clocklist
            comboBox_clocklist.Items.Clear();
            comboBox_clocklist.Items.AddRange(m_clockList);
            comboBox_clocklist.SelectedItem = m_ncurclockselect;
            comboBox_clocklist.Text = m_clockList[m_ncurclockselect];
            //更新灰度等级List
            comboBox_grayLevelList.Items.Clear();
            comboBox_grayLevelList.Items.AddRange(m_grayList);
            comboBox_grayLevelList.SelectedIndex = m_ncurgrayslect;
            comboBox_grayLevelList.Text = m_grayList[m_ncurgrayslect];
            m_strgrayindextext = m_grayList[m_ncurgrayslect];
            
            //更新界面上其他参数
            textBox_clockduty.Text = m_nclockduty;
            textBox_graystart.Text = m_ngraystart;
            textBox_low_gray_smooth.Text = m_low_gray_smooth;
            textBox_gamavalue.Text = m_ngama;
            checkBox_openprotect.Checked = m_bopenprotect;
            checkBox_colorRe.Checked = m_bcolorRe;
            checkBox_ReCardWidth.Checked = m_bReciveWidth;
            checkBox_NSlastFrame.Checked = m_bNsigle;
            checkBox_keep.Checked = m_cProtectCP;

            if (m_eadjust == 1)
                button_eadjust.Show();
            else
                button_eadjust.Hide();
        }

        private void textBox_gamavalue_TextChanged(object sender, EventArgs e)
        {
            string tempstr = textBox_gamavalue.Text;
            try
            {
                System.Double.Parse(tempstr);
            }
            catch
            {
                MessageBox.Show("输入格式不对，此处只能识别整数,且不能为空");
                textBox_gamavalue.Text = m_ngama;
            }
            m_ngama = textBox_gamavalue.Text;
        }
        private void checkBox_openprotect_CheckedChanged(object sender, EventArgs e)
        {
            m_bopenprotect = checkBox_openprotect.Checked;
        }

        private void checkBox_colorRe_CheckedChanged(object sender, EventArgs e)
        {
            m_bcolorRe = checkBox_colorRe.Checked;
        }

        private void checkBox_ReCardWidth_CheckedChanged(object sender, EventArgs e)
        {
            m_bReciveWidth = checkBox_ReCardWidth.Checked;
        }

        private void checkBox_NSlastFrame_CheckedChanged(object sender, EventArgs e)
        {
            m_bNsigle = checkBox_NSlastFrame.Checked;
        }
        private void comboBox_clocklist_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_ncurclockselect = comboBox_clocklist.SelectedIndex;
        }
        private void comboBox_grayLevelList_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_ncurgrayslect = comboBox_grayLevelList.SelectedIndex;
            m_strgrayindextext = m_grayList[m_ncurgrayslect];
        }
        private void textBox_clockduty_TextChanged(object sender, EventArgs e)
        {
            string tempstr = textBox_clockduty.Text;
            try
            {
                System.Int32.Parse(tempstr);
            }
            catch
            {
                MessageBox.Show("输入格式不对，此处只能识别整数,且不能为空");
                textBox_clockduty.Text = m_nclockduty;
            }
            m_nclockduty = textBox_clockduty.Text;
        }
        private void textBox_low_gray_smooth_TextChanged(object sender, EventArgs e)
        {
            string tempstr = textBox_low_gray_smooth.Text;
            try
            {
                System.Int32.Parse(tempstr);
            }
            catch
            {
                MessageBox.Show("输入格式不对，此处只能识别整数,且不能为空");
                textBox_low_gray_smooth.Text = m_low_gray_smooth;
            }
            m_low_gray_smooth = textBox_low_gray_smooth.Text;
        }
        private void textBox_graystart_TextChanged(object sender, EventArgs e)
        {
            string tempstr = textBox_graystart.Text;
            try
            {
                System.Int32.Parse(tempstr);
            }
            catch
            {
                MessageBox.Show("输入格式不对，此处只能识别整数,且不能为空");
                textBox_graystart.Text = m_ngraystart;
            }
            m_ngraystart = textBox_graystart.Text;
        }

        private void comboBox_clocklist_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void Application_button_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            m_cProtectCP = checkBox_keep.Checked;
        }
    }
}
